function [ gradA ] = assemblyGradMomentMatrix( x, xNodes, gradWeights, poliBaseType, order )
%ASSEMBLYMOMENTMATRIX Assembles the moment matrix spational gradient
%                     for a sample point. 
%   INPUT:
%
%   x            : Sample point.
%   xNodes       : List of all domain's nodes.
%   gradWeights  : Spatial gradient of the weight function evaluated at
%                  each point.
%   poliBaseType : Type of the polinomial base of p(x).
%   order        : Order of the polinomial base of p(x).
%
%   OUTPUT:
%
%   A            : Spatial gradient of the moment matrix, a three
%                  dimensional matrix, where the last dimension states for
%                  the spatial dimension.

% p(x) = poliBase(x,k,'baseType'); % Vector p(x) - Not bases yet

dimension = size(x,2);
nBaseElements = getPolibaseDimension (order);

gradA = zeros(nBaseElements, nBaseElements, dimension);

for d = 1 : dimension;
    GA = zeros (nBaseElements,nBaseElements);
    for a = 1:size(xNodes,1);
        p_xa = poliBase(xNodes(a,:), order, poliBaseType);
    
        if (gradWeights(a) ~= 0);
           GA = GA + gradWeights(a,d) *...
                          tensorProduct(p_xa, p_xa, size(p_xa,2));
        end;
    end;
    gradA(:,:,d) = GA;
end;

end

